package com.srit.recipes.entity;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.lang.annotation.Annotation;
import java.util.Date;

@Table
@Entity
@Getter
@Setter
@EntityListeners(AuditingEntityListener.class)
public class ProcurementDetailInfo extends RecipesId {

    public static final int IN_CREATE = 0;
    public static final int IN_EXAMINE = 1;
    public static final int EXAMINE_FAILED = 2;
    public static final int EXAMINE_PASS = 3;

    @ExcelIgnore
    private int recipesId;

    @ExcelProperty("食材名称")
    private String name;

    @ExcelProperty("采购数量")
    private Long wight;

    @ExcelProperty("单位")
    private String unit;

    @Column
    @ExcelProperty(value = "日期", converter = Day.class)
    private Integer week;

    /**
     * 剩余库存
     */
    @Transient
    @ExcelProperty(value = "剩余库存")
    private long inventoryLeft = 0;

    @Transient
    private Double price;

    public static class Day implements Converter<Integer> {

        @Override
        public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
            return new WriteCellData<>(value.toString());
        }
    }


}
